/**
 * 将一个对象中的 keys 移除获得一个新对象
 * 
 * @param {Object} obj {}
 * @param {Object} keys ['key1', 'key2']
 */
function removeKeys(obj, keys) {
	const result = {};
	for (const key in obj) {
		if (!keys.includes(key)) {
			result[key] = obj[key];
		}
	}
	return result;
}

/**
 * 源同属性赋值到目标
 * @param {Object} source
 * @param {Object} target
 */
function assign(source, target, incCols, excCols) {
	if (incCols && incCols.length > 0) {
		for (let key in source) {
			if (target.hasOwnProperty(key) && incCols.includes(key)) {
				target[key] = source[key]
			}
		}
	} else if (excCols && excCols.length > 0) {
		for (let key in source) {
			if (target.hasOwnProperty(key) && !excCols.includes(key)) {
				target[key] = source[key]
			}
		}
	} else {
		for (let key in source) {
			if (target.hasOwnProperty(key)) {
				target[key] = source[key]
			}
		}
	}
}

const ObjUtil = {
	removeKeys,
	assign
}

export default ObjUtil